# encoding=utf8
import sys
import time
import math
reload(sys)
sys.setdefaultencoding('utf8')

class JT_0702:
  def LogicAisle(self, protocolStr, header):
    result=[]
    count=0
    s = protocolStr[count:count + 2]
    header.append("状态:")
    if s=='01':
        header.append("从业资格证 IC 卡插入（驾驶员上班）"+"\n")
        count = count + 2
        s = protocolStr[count:count + 12]
        c = 0
        t = s[c:c + 2]
        header.append("时间：" + t)
        c = c + 2
        for i in range(5):
            t = s[c:c + 2]
            header.append("-" + t)
            c = c + 2
        count = count + 12
        s = protocolStr[count:count + 2]
        count = count + 2
        header.append("\n")
        if s=="00":
         header.append("IC 卡读卡成功；" +"\n")
         s = protocolStr[count:count + 2]
         n=int(s,16)
         header.append("\n"+"驾驶员姓名长度:"+str(n)+"\n")
         count = count + 2
         s = protocolStr[count:count+2*n]
         header.append("驾驶员姓名:"+s.decode("hex").decode('gb2312')+"\n")
         count = count + 2*n

         s = protocolStr[count:count + 40]
         header.append("从业资格证编码:" + s.decode("hex").decode('gb2312') + "\n")
         count = count + 40

         s = protocolStr[count:count + 2]
         m = int(s, 16)
         header.append("\n" + "发证机构名称长度:" + str(m)+"\n")
         count = count + 2
         s = protocolStr[count:count + 2 * m]
         header.append("发证机构名称:" + s.decode("hex").decode('gb2312') + "\n")
         count = count + 2 * m

         s = protocolStr[count:count + 8]
         header.append("证件有效期 :" + s + "\n")
        elif s=="01":
            header.append("读卡失败，原因为卡片密钥认证未通过;" + "\n")
        elif s=="02":
            header.append("读卡失败，原因为卡片已被锁定; " + "\n")
        elif s=="03":
            header.append("读卡失败，原因为卡片被拔出;" + "\n")
        elif s=="04":
            header.append("读卡失败，原因为数据校验错误;" + "\n")


    elif s=="02":
        header.append("从业资格证 IC 卡拔出（驾驶员下班）"+"\n")

    self.result = header
